<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box{
           display: flex;
        }
        .left{
            width: 200px;
            height: 700px;
            background-color: aqua;
            display: inline-block;
        }
        .right{
            width: 100%;
            height: 700px;
            background-color: yellow;
            display: inline-block;
            
        }
    </style>
</head>
<body>
    <div class="box">
        <div class="left">
            <ul>
                <li>首页</li>
                <li>用户管理</li>
                <li>权限管理</li>
                <li>新闻管理</li>
            </ul>
        </div>
        <div class="right">
            <div class="bread"></div>
        </div>
    </div>
</body>
<script>
    //观察目标
    class Subject{
            constructor(){
                this.observer = []
            }
            //加入观察方法
            add(observer){
                this.observer.push(observer)
            }
            //退出观察方法
            remove(observer){
                this.observer = this.observer.filter(
                    item => item !== observer
                )
            }
            //更新观察内容方法
            notify(data){
                this.observer.forEach(item=>{
                    
                    item.update(data)
                })
            }
        }

        //观察者
        class Observer{
            constructor(name){
                this.el=document.querySelector(name)
            }
            update(data){
                this.el.innerHTML = data
            }
        }

        const subject = new Subject();
        
        // 实例化观察者，并传递节点
        const observer = new Observer(".bread")
        //加入观察
        subject.add(observer)


        let lis = document.querySelectorAll("li")


        for (let i = 0; i < lis.length; i++) {
            lis[i].onclick = function () {
                //调用更新内容并传递参数
                subject.notify(this.innerHTML)
            }
        }
</script>
</html>